package jzoffer;

/**
 * Author:   dengxin
 * Date:     2020/6/17 3:56 下午
 * 斐波拉契数列
 */
public class jz7 {

    public static void main(String[] args) {
        System.out.println(fibonacci(5));
    }

    private static int fibonacci(int n) {
        if (n == 0) {
            return 0;
        }
        if (n==1 || n==2) {
            return 1;
        }
        int one = 1;
        int two = 1;
        int temp;
        for (int i=3; i<=n; i++) {
            temp = one;
            one = two;
            two = temp + one;
        }
        return two;
    }
}
